<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Order Processing</title>

  <style>
    /* 页面整体样式 */
    body {
      font-family: "Helvetica Neue", Arial, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f9f9f9;
    }

    .container {
      width: 70%;
      margin: 30px auto;
      padding: 20px 30px;
      background: #ffffff;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    }

    h2 {
      text-align: center;
      color: #734012;
      font-size: 28px;
      margin-bottom: 30px;
    }

    .tabs {
      display: flex;
      justify-content: center;
      margin-bottom: 30px;
      border-bottom: 2px solid #ddd;
    }

    .tab {
      padding: 10px 20px;
      cursor: pointer;
      font-weight: bold;
      color: #555;
      transition: color 0.3s ease, border-bottom 0.3s ease;
    }

    .tab.active {
      border-bottom: 3px solid #fccc1c;
      color: #734012;
    }

    .tab:hover {
      color: #734012;
    }

    .tab-content {
      display: none;
    }

    .tab-content.active {
      display: block;
    }

    /* 表格样式 */
    table {
      border-collapse: separate;
      border-spacing: 12px;
      width: 100%;
      margin: 20px 0;
    }

    td, th {
      padding: 12px 16px;
      text-align: center;
      vertical-align: middle;
      background-color: #fffbe6;
      border-radius: 8px;
      transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    th {
      font-weight: bold;
      background-color: #fccc1c;
      color: #734012;
      text-transform: uppercase;
    }

    tr:hover {
      transform: scale(1.02);
      box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    }

    tr:nth-child(odd) td {
      background-color: rgba(252, 204, 28, 0.15);
    }

    tr:nth-child(even) td {
      background-color: rgba(252, 204, 28, 0.05);
    }

    /* 输入框和按钮样式 */
    label {
      display: block;
      margin: 10px 0 5px;
      color: #555;
      font-weight: bold;
    }

    input, select {
      width: calc(100% - 20px);
      padding: 10px;
      margin-bottom: 15px;
      border: 1px solid #ddd;
      border-radius: 5px;
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    button {
      display: block;
      background-color: #fccc1c;
      color: #ffffff;
      padding: 12px 20px;
      border: none;
      border-radius: 6px;
      font-size: 16px;
      font-weight: bold;
      cursor: pointer;
      margin-top: 10px;
      transition: background-color 0.3s ease, color 0.3s ease;
    }

    button:hover {
      background-color: #734012;
      color: #ffffff;
    }
  </style>
</head>
<body>
<header th:replace="common/top"></header>
<div class="container">
  <h2>Order Processing</h2>
  <div class="tabs">
    <div class="tab active" data-tab="orderInfo" onclick="showTab('orderInfo')">Order Items</div>
    <div class="tab" data-tab="paymentInfo" onclick="showTab('paymentInfo')">Payment Info</div>
    <div class="tab" data-tab="shippingInfo" onclick="showTab('shippingInfo')">Shipping Info</div>
  </div>

  <form id="OrderTabsForm" th:action="@{/order/submitOrder(username=${session.loginAccount.username})}" method="post">
    <div class="tab-content active" id="orderInfo">
      <h3>Order Items</h3>
      <table>
        <tr>
          <th>Item ID</th>
          <th>Item Name</th>
          <th>Quantity</th>
          <th>Price</th>
          <th>Total</th>
        </tr>
        <tr th:each="cartItem : ${cart}">
          <td th:text="${cartItem.item.itemId}"></td>
          <td th:text="${products[cartItem.item.productId].productName}"></td>
          <td th:text="${cartItem.number}"></td>
          <td th:text="${cartItem.item.listPrice}"></td>
          <td th:text="${subtotal}"></td>
        </tr>
        <tr>
          <td colspan="5">Sub Total: <span th:text="${subtotal}"></span></td>
        </tr>
      </table>
      <button type="button" onclick="showTab('paymentInfo')">Next</button>
    </div>

    <div class="tab-content" id="paymentInfo">
      <h3>Payment Info</h3>
      <label for="cardType">Card Type</label>
      <select name="order.cardType" id="cardType" required>
        <option value="Visa" th:selected="${cardType == 'Visa'}">Visa</option>
        <option value="MasterCard" th:selected="${cardType == 'MasterCard'}">MasterCard</option>
      </select>
      <label for="creditCard">Credit Card Number</label>
      <input type="text" name="order.creditCard" id="creditCard" value="999 9999 9999 9999" required>
      <label for="expiryDate">Expiry Date</label>
      <input type="text" name="order.expiryDate" id="expiryDate" value="12/03" required>
      <button type="button" onclick="showTab('shippingInfo')">Next</button>
    </div>

    <div class="tab-content" id="shippingInfo">
      <h3>Shipping Info</h3>
      <label for="shipToFirstName">First Name</label>
      <input type="text" name="order.shipToFirstName" id="shipToFirstName" th:value="${session.loginAccount?.firstName}" required>
      <label for="shipToLastName">Last Name</label>
      <input type="text" name="order.shipToLastName" id="shipToLastName" th:value="${session.loginAccount?.lastName}" required>
      <label for="shipAddress1">Address</label>
      <input type="text" name="order.shipAddress1" id="shipAddress1" th:value="${session.loginAccount?.address1}" required>
      <label for="shipCity">City</label>
      <input type="text" name="order.shipCity" id="shipCity" th:value="${session.loginAccount?.city}" required>
      <label for="shipState">State</label>
      <input type="text" name="order.shipState" id="shipState" th:value="${session.loginAccount?.state}">
      <label for="shipZip">ZIP Code</label>
      <input type="text" name="order.shipZip" id="shipZip" th:value="${session.loginAccount?.zip}">
      <button type="submit">Confirm Order</button>
    </div>
  </form>
</div>

<script>
  function showTab(tabId) {
    document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
    document.getElementById(tabId).classList.add('active');
    document.querySelectorAll('.tab').forEach(tab => tab.classList.remove('active'));
    document.querySelector(".tab[data-tab='" + tabId + "']").classList.add('active');
  }
</script>
</body>
</html>
